package com.gxa.service.impl;

import com.gxa.common.JsonResult;
import com.gxa.common.PageRecv;
import com.gxa.common.R;
import com.gxa.mapper.InterBulletinMapper;
import com.gxa.pojo.Interbulletin;
import com.gxa.service.InterBulletinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InterBulletinServiceImpl implements InterBulletinService {
    @Autowired(required = false)
    private InterBulletinMapper interBulletinMapper;

    @Override
    public JsonResult queryIntBullList(Integer currentPage, Integer pageSize) {
        JsonResult jsonResult=new JsonResult();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize*currentPage;
        List<Interbulletin> repositoryList=interBulletinMapper.queryIntBu(param1,param2);
        int count =interBulletinMapper.countqueryIntBu() ;
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功！");
        jsonResult.setData(repositoryList);
        jsonResult.setCount(count);
        return jsonResult;
    }

    @Override
    public R addIntBu(Interbulletin interbulletin) {
        R r=new R();
        interBulletinMapper.addIntBu(interbulletin);
        r.setCode(200);
        r.setMsg("添加成功！");
        return r;
    }

    @Override
    public R delIterB(Integer id) {
        R r=new R();
        interBulletinMapper.delIterB(id);
        r.setCode(200);
        r.setMsg("删除成功！");
        return r;
    }

    @Override
    public JsonResult selectInterB(PageRecv<Interbulletin> pageRecv) {
        //对查询页面参数计算
        Integer currentPage=pageRecv.getCurrentPage();
        Integer pageSize=pageRecv.getPageSize();
        Integer limit1=(currentPage-1)*pageSize;
        pageRecv.setCurrentPage(limit1);
        //获取查询条件实体
        Interbulletin interbulletin = pageRecv.getData();
//      System.out.println(repository);
        //调用mapper方法，返回查询结果list
//        System.out.println("---进入service层---");
        List<Interbulletin> list=interBulletinMapper.selectInterB(pageRecv);
        Integer count=interBulletinMapper.countselectInterB(pageRecv);
        //将list和count条数塞入r,响应成功返回
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setCount(count);
        r.setMsg("搜索成功");
        r.setData(list);
        return r;
    }

    @Override
    public R replyInterB(Interbulletin interbulletin) {
        R r=new R();
        interBulletinMapper.replyInterB(interbulletin);
        r.setCode(200);
        r.setMsg("回复成功！");
        return r;
    }

    @Override
    public R updateInterB(Interbulletin interbulletin) {
        R r=new R();
        interBulletinMapper.updateInterB(interbulletin);
        r.setCode(200);
        r.setMsg("修改成功！");
        return r;
    }


}
